package com.huike.business.service.impl;


import com.github.pagehelper.Page;
import com.huike.business.domain.TbBusiness;
import com.huike.business.domain.vo.BusinessTrackVo;
import com.huike.business.mapper.TbBusinessTrackRecordMapper;
import com.huike.business.service.ITbBusinessService;
import com.huike.business.service.ITbBusinessTrackRecordService;
import com.huike.common.core.page.TableDataInfo;
import com.huike.common.utils.SecurityUtils;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 商机跟进记录Service业务层处理
 * 
 * @author wgl
 * @date 2021-04-28
 */
@Service
public class TbBusinessTrackRecordServiceImpl implements ITbBusinessTrackRecordService {
    @Autowired
    private TbBusinessTrackRecordMapper tbBusinessTrackRecordMapper;

    @Autowired
    private ITbBusinessService tbBusinessService;
    //新增商机跟进记录
    @Override
    public String addBusinessTrackVo(BusinessTrackVo businessTrackVo) {
       /* String username = SecurityUtils.getUsername();
        businessTrackVo.setCreateBy(username);
        tbBusinessTrackRecordMapper.addTbBusinessTrackRecord(businessTrackVo);
        tbBusinessTrackRecordMapper.updateTbBusiness(businessTrackVo);
        return "success";*/



        //最终要插入的数据
        BusinessTrackVo businessVo=new BusinessTrackVo();
        String username = SecurityUtils.getUsername();
        //复制商机跟进记录
        BeanUtils.copyProperties(businessTrackVo,businessVo);
        businessTrackVo.setCreateBy(username);
        //获得商机
        TbBusiness tbBusiness = tbBusinessService.selectTbBusinessById(businessTrackVo.getBusinessId());
        //将商机跟进记录里面的有用的数据给商机
        BeanUtils.copyProperties(businessTrackVo,tbBusiness);
        tbBusinessTrackRecordMapper.addTbBusinessTrackRecord(businessVo);
        tbBusinessService.updateTbBusiness(tbBusiness);
        return "success";
    }
    //查询商机跟进记录
    @Override
    public List<BusinessTrackVo> selectBusinessTrackVo(Long id) {
      return  tbBusinessTrackRecordMapper.SelectBusinessTrackVo(id);
    }
}
